<?php 

function debug($arg, $die = true)
{
	echo '<pre>'; echo gettype($arg) . ': ';  print_r($arg); echo '</pre>';
	if($die == true)
	{
		die();
	}
}


function redirect($url, $code = '301')
{
	header('Location:'.$url);
    die();
}

function __autoload($class)
{
	global $conf;
	if( isset($conf['INCLUDE_PATHS']) && is_array($conf['INCLUDE_PATHS']) )	
	{
		foreach($conf['INCLUDE_PATHS'] as $path)
		{
			$file = $path . $class . '/class.' . $class . '.php';
			if(file_exists($file))
			{
				include $file;
				return true;
			}
		}
		return false;
	}
}

function isDevMode($ipAddr)
{
	global $conf;
	if(in_array($ipAddr, $conf['DEV_IP']) && !isset($_GET['devModeOff']))
	{
		return true;
	}
	return false;
}


function url($add = array(), $remove=array())
{
	global $conf;
	if(!isset($conf['smarty_plugins_dir'][0]))
	{
		return;
	}
	
	$addString = '';
	foreach($add as $key=>$val)
	{
		$addString .= $key.'='.$val.',';
	}
	if(strlen($addString)>0) 
	{ 
		$addString = substr($addString, 0, -1);
	}
	
	$removeString = '';
	foreach($remove as $key=>$val)
	{
		$removeString .= $key.'='.$val.',';
	}
	if(strlen($removeString)>0) 
	{ 
		$removeString = substr($removeString, 0, -1);
	}
	
	include ($conf['smarty_plugins_dir'][0] . 'function.url.php');
	$params = array('add' => $addString, 'remove' => $removeString);
	return str_replace('&amp;', '&', smarty_function_url($params));
}


?>